package com.clock.service.impl;

import com.clock.domain.dto.UserByManagerDTO;
import com.clock.domain.entity.User;
import com.clock.mapper.UserMapper;
import com.clock.service.AuthorizationService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service("authorizationService")
public class AuthorizationServiceImpl implements AuthorizationService {

    @Resource
    UserMapper userMapper;

  /*  @Override
    public boolean setAuthorization(User user) {
        if(userRole.getGranterId() == null||userRole.getGrantername()==null
                ||userRole.getUserId()==null ||userRole.getRoleId() ==null){
            return false;
        }
        if(userRole.getGranttime()==null){
            userRole.setGranttime(DateUtil.date());
        }

        int insert = userRoleMapper.insert(userRole);
        return insert>=1;
        return false;
    }*/

    @Override
    public boolean updateAuthorization(UserByManagerDTO userByManagerDTO) {
        User user = userMapper.queryById(userByManagerDTO.getManagerId().intValue());
        if(user.getUserRoleId()!=1){
            return false;
        }else{
            int i = userMapper.updateUserRoleId(userByManagerDTO.getUserId(), userByManagerDTO.getUserNewRoleId());
            return  i >= 1;
        }
    }


}
